/*
 * Achieve it All! - Android app to motivate achieving your goals
 * Copyright (C) 2014  Xilconic
 * 
 * This file is part of Achieve it All!.
 *
 * Achieve it All! is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Achieve it All! is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Achieve it All!.  If not, see <http://www.gnu.org/licenses/>
 */
package com.xilconic.achieveitall.persist;

import java.util.ArrayList;

import android.provider.BaseColumns;

/**
 * This class defines the database structure for the 'Achieve it all' application.
 * @author Xilconic
 *
 */
public final class AchieveItAllDatabaseContract {
    public static final String DATABASE_NAME = "achieveitall.db";
    
	public AchieveItAllDatabaseContract(){}
	
	/**
	 * Contract definition for persisting {@link Target} to the database.
	 * @author Xilconic
	 *
	 */
	public static final class TargetContract implements BaseColumns{
		/**
		 * Name of the table storing all created {@link Target} instances.
		 */
		public static final String TABLE_NAME = "targets";
		
		/**
		 * The name of a {@link Target}, as {@link SqliteDataType#Text}.
		 */
		public static final String COLUMN_NAME_NAME = "name";
		/**
		 * The description of a {@link Target}, as {@link SqliteDataType#Text}.
		 */
		public static final String COLUMN_NAME_DESCRIPTION = "description";
		/**
		 * The finished state of a {@link Target}, as {@link SqliteDataType#Integer}.
		 */
		public static final String COLUMN_NAME_IS_FINISHED = "isFinished";
		/**
		 * The amount of points that can be score for finishing a {@link Target},
		 * as {@link SqliteDataType#Integer}.
		 */
		public static final String COLUMN_NAME_POINTS_REWARD = "pointsReward";
		
		private static int NUMBER_OF_COLUMNS = 6;
		
		/**
		 * Returns the SQL statement to create this table in the database.
		 * @return The SQL statement.
		 */
        public static String getTableCreationString() {
            ArrayList<ColumnTableDefinition> columnDefinitions = new ArrayList<ColumnTableDefinition>(NUMBER_OF_COLUMNS);
            columnDefinitions.add(new ColumnTableDefinition(_ID, SqliteDataType.PrimaryKey));
            columnDefinitions.add(new ColumnTableDefinition(_COUNT, SqliteDataType.Integer));
            columnDefinitions.add(new ColumnTableDefinition(COLUMN_NAME_NAME, SqliteDataType.Text));
            columnDefinitions.add(new ColumnTableDefinition(COLUMN_NAME_DESCRIPTION, SqliteDataType.Text));
            columnDefinitions.add(new ColumnTableDefinition(COLUMN_NAME_IS_FINISHED, SqliteDataType.Integer));
            columnDefinitions.add(new ColumnTableDefinition(COLUMN_NAME_POINTS_REWARD, SqliteDataType.Integer));

            assert(columnDefinitions.size() == NUMBER_OF_COLUMNS);
            
            return SqliteHelpers.getStringCreateTable(TABLE_NAME, columnDefinitions);
        }

        public static String[] getAllColumns() {
            // TODO Auto-generated method stub
            String[] columns = new String[]{ _ID, _COUNT, COLUMN_NAME_NAME, COLUMN_NAME_DESCRIPTION, 
                                             COLUMN_NAME_IS_FINISHED, COLUMN_NAME_POINTS_REWARD };
            
            assert(columns.length == NUMBER_OF_COLUMNS);
            
            return columns;
        }
	}
}
